package com.dingding.service.core.common.dao.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.daox.IBaseDaoX;
import com.dingding.common.core.base.daox.ICriteriaBaseDao;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.ChannelRefUser;
import com.dingding.service.core.common.dao.IChannelRefUserDao;
import com.dingding.service.core.common.sql.ChannelSQL;

/**
 * 
 * @ClassName: DriverRefChannelDaoImpl 
 * @Description: 
 * @author hufan
 * @date 2016年12月21日 下午1:06:40 
 *
 */
@Component("channelRefUserDao")
public class ChannelRefUserDaoImpl implements IChannelRefUserDao {

	@Resource(name = "SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;

	@Resource(name = "criteriaBaseDao")
	private ICriteriaBaseDao criteriaBaseDao;

	@Resource(name = "baseDaoX")
	private IBaseDaoX baseDaoX;
	
	/**
	 * 
	 * @Title: saveChannelRefUser 
	 * @Description: 保存用户关联来源渠道
	 * @param  参数说明 
	 * @author hufan
	 * @return 返回类型 
	 * @throws
	 */
	@Override
	@Transactional(propagation = Propagation.REQUIRED)
	public boolean saveChannelRefUser(ChannelRefUser channelRefUser) {
		
		if(channelRefUser == null) {
			return false;
		}
		
		return baseDaoX.save(channelRefUser);
	}

	/**
	 * 
	 * @Title: queryChannelRefUserByUserId 
	 * @Description: 根据用户id查询该用户的来源渠道
	 * @param  参数说明 
	 * @author hufan
	 * @return 返回类型 
	 * @throws
	 */
	@Override
	@Transactional(readOnly = true)
	public ChannelRefUser queryChannelRefUserByUserId(String userId) {
		
		if(userId == null) {
			return null;
		}
		
		return sqlBaseDao.sqlToCustomBeanUnique(ChannelRefUser.class, ChannelSQL.QUERY_CHANNEL_REF_USER_BY_USERID, userId);
	}

}
